package fun.cyhgraph.service.serviceImpl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import fun.cyhgraph.common.ErrorCode;
import fun.cyhgraph.exception.BusinessException;
import fun.cyhgraph.exception.ThrowUtils;
import fun.cyhgraph.mapper.MerchantInfoMapper;
import fun.cyhgraph.mapper.UserMapper;
import fun.cyhgraph.model.dto.*;
import fun.cyhgraph.model.entity.MerchantInfo;
import fun.cyhgraph.model.entity.User;
import fun.cyhgraph.model.vo.UserLoginVO;
import fun.cyhgraph.properties.WeChatProperties;
import fun.cyhgraph.result.Result;
import fun.cyhgraph.service.MerchantInfoService;
import fun.cyhgraph.service.UserService;
import fun.cyhgraph.utils.HttpClientUtil;
import fun.cyhgraph.utils.SqlUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import static fun.cyhgraph.common.UserConstant.USER_LOGIN_STATE;

@Service
public class MerchantInfoServiceImpl extends ServiceImpl<MerchantInfoMapper, MerchantInfo> implements MerchantInfoService {


    @Override
    public MerchantInfo judgeMerchantInfo(Integer merchantId) {
        //查询merchant是否存在
        LambdaQueryWrapper<MerchantInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MerchantInfo::getMerchantId, merchantId);
        MerchantInfo one = getOne(queryWrapper);
        ThrowUtils.throwIf(merchantId == null , ErrorCode.NOT_FOUND_ERROR , "商户不存在");
        if (one == null){
            throw new BusinessException(ErrorCode.FORBIDDEN_ERROR , "商户不存在");
        }
        return one;
    }
}
